 <template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <el-input
          v-model="query.contactPersion"
          clearable
          placeholder="输入姓名"
          style="width: 200px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        />

      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->

      <crudOperation :permission="permission"/>

      <!--表单组件-->
      <el-dialog
        :close-on-click-modal="false"
        :before-close="crud.cancelCU"
        :visible.sync="crud.status.cu > 0"
        :title="crud.status.title"
        width="500px"
      >
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="手机号" prop="contactPhone">
            <el-input v-model="form.contactPhone" style="width: 370px;"  maxlength="11" placeholder="预留手机号"  type="number" />
          </el-form-item>
          <el-form-item label="联系人" prop="contactPersion">
            <el-input v-model="form.contactPersion" style="width: 370px;"   maxlength="5" placeholder="联系人"/>
          </el-form-item>
          <el-form-item label="微信" prop="contactWeixin">
            <el-input v-model="form.contactWeixin" style="width: 370px;" maxlength="30" placeholder="预留微信"  />
          </el-form-item>
          <el-form-item label="地址"  prop="adress">
            <el-input v-model="form.adress" style="width: 370px;"type="textarea"  maxlength="100" placeholder="地址" rows="3"/>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->


      <!--表格渲染-->
      <el-table
        ref="table"
        v-loading="crud.loading"
        :data="crud.data"
        size="small"
        style="width: 100%;"
        @selection-change="crud.selectionChangeHandler"
      >
        <el-table-column :selectable="checkboxT" type="selection" width="55" />
        <el-table-column :show-overflow-tooltip="true" prop="contactPhone" label="手机号"/>
        <el-table-column :show-overflow-tooltip="true" prop="contactPersion" label="联系人" />
        <el-table-column :show-overflow-tooltip="true" width="125" prop="contactWeixin" label="微信" />
        <el-table-column :show-overflow-tooltip="true" prop="adress" width="100" label="地址" />
        <el-table-column prop="createTime" label="创建时间">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime) }}</span>
          </template>
        </el-table-column>


        <el-table-column v-permission="['admin','testWater:edit','testWater:del']" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation :data="scope.row" :permission="permission"/>
          </template>
        </el-table-column>

      </el-table>
      <!--分页组件-->

      <pagination/>

    </div>
  </div>
</template>









<script>
  import crudTest from '@/api/wedding'   //数据 接口


  import CRUD, {presenter, header, form, crud} from '@crud/crud'  //


  import rrOperation from '@crud/RR.operation'
  import crudOperation from '@crud/CRUD.operation' //列表 删除修改按钮
  import udOperation from '@crud/UD.operation'  //列表删除提示框


  // 分页 组件
  import pagination from '@crud/Pagination'


  // crud交由presenter持有
  //定义请求数据，
  const defaultCrud = CRUD({
    title: '',
    url: 'api/wedding',
    method: 'post',
    sort: 'id,desc',
    crudMethod: { ...crudTest }
  })



  const defaultForm = {
    id:
      null,
    contactPhone:
      null,
    contactPersion:
      null,
    adress:
      null,
    contactWeixin:
      null,
    createTime:
      null
  }



  export default {
    name: 'Test',
    components: { pagination, crudOperation, rrOperation, udOperation },

    mixins: [presenter(defaultCrud), header(), form(defaultForm), crud()], //请求列表数据


    data() {
      return {
        permission: {
          add: ['admin', 'wedding:add'],
          edit: ['admin', 'wedding:edit'],
          del: ['admin', 'wedding:del']
        },
        rules: {

          contactPhone:
            [
              {required: true, message: '手机号不能为空', trigger: 'blur'}
            ],
          contactPersion:
            [
              {required: true, message: '联系人不能为空', trigger: 'blur'}
            ],
          contactWeixin:
            [
              {required: true, message: '微信不能为空', trigger: 'blur'}
            ],
          adress:
            [
              {required: true, message: '地址不能为空', trigger: 'blur'}
            ]
        },
        queryTypeOptions: [
          {
            key: 'id',
            display_name: 'id'
          },
          {
            key: 'email',
            display_name: '邮箱'
          },
          {
            key: 'username',
            display_name: '用户名'
          }
        ]
      }
    },




    methods: {
      // 获取数据前设置好接口地址
      [CRUD.HOOK.beforeRefresh]() {
        const query = this.query

        if (query.type && query.value) {
          this.crud.params[query.type] = query.value
        }
        return true
      }
    }
  }
</script>
<style scoped>
</style>
